More bug fixes, in prepartion for porting to web app.