fixed bugs,refactored