js optimisations and style fixes