add commets and fix bugs