refactoring
fixed edge case