minor optimisations + cleanup