#330 Tidied up the code, fixed some layout problems