remove most inline functions and fix reference bugs