refactored compile functions