added guards and exceptions