optimised slightly