Github has killed the indentation but basically the code could be cleaner.