refactoring "else if"
refactoring, removed isinterrupted check
fixed performance issue
removed try block