Bigass refactor of the code, looks pretty nice now, and with less code