Small fixes and code cleanup