Tidied up, added more logic and redesign