restoring original code and fix a bug.