Bug fixes and input checks