Fixed a few bugs, wrong mappings, and some more code cleanup.