moved related functions to top