some refactorings, added more scenarios