DRYer code; added tests (Karma, Protractor)