Properly handle branching

fix a few bugs
Add register IO ram