code refactor

 - removed unneeded code
 - created and used functions where helpful
 - some typos found and fixed
 - moved formatting code to style header where it should have been