Code cleanup & optimisations