Major refactor & optimisations