Completely refactored files, added rudimentary documentation