castling logic rewrite as preparation for #15
should fix 1, 2 and 4 of #15
fixed #15