Cleaning files, refactoring, and redoing lua implementation