Cleaned up main file, and made code faster