Formatting + removal of unused code + make some variables local

Signed-off-by: Ollie <dzineit@live.co.uk>