reordered functions and made some things private