Initial commit.
Quick fix...
Updated with constants magic, does not work right but commited for reference.
Cleaned up the codebase a little.