added more functionality and checks
fixed small bug