Refactored code to meet Moodle coding standards, improved function to determine when enough data has been enrolled