refactored optimized code. Clean up unsused members and comments