moved some things to inline functions
edited to match changes