Tidied Code
Did cursory to-compile check