Tidy up code whilst trying to find out whats not working