Added test and some errorhandling