Added checking by interval and refactoring