Refactored. Added more bitwise and integer logic, removed a lot of lines, cleaned up CSS and HTML a bit.