bug fixes and cleanup!