Reverted the last few commits, as they were not properly tested

This reverts commit 1c7ffa0c4d2e26c22f480fc27b6e2e287fb030cf.