Tidied code.
Removed test code form main.