fixes and code cleanup