Fixing issue #5

This is untested code. I will test everything during the weekend.