mass refactor of extension and small bug-fixing.