Several bug fixes

Program is now partially running