refactoring,bug fixes