refactored a bug fix