refectored initCastle Function for better code