Changed implementation as suggested by #197