Bug fixes and nicer errors