bugs fixed

code still needs cleaning up, but appearing well functional