implemented guard and refactored tests