Bug fixes and better validation