Modified according to comments by tralamazza