Made some code style fixes and minor optimisations