fixes and optimisations p1