cleaned up main functions