Cleaned up code and refactored. Need to adress the alignement problem