How were castles built / constructed in the medieval period?