Committing code.

API is property of @MineMaarten
Rest of the code by me (With exceptions of snippets from @Pahimar's LMRB)