Some small optimisations
Further optimisations; more comments explaining structure