fixed whitespaces, tidied up code