Move function definitions into function being exported