move code to correct function