Clean up and logging added

Signed-off-by: Justin Wiblin <Justin_wiblin@hotmail.co.uk>