extensive bug-fixing