Working version with some test on caclulation and catching wrong input