Bug fixes and testing