code refactoring, fixed errors, fixed warnings.