Rec bugfixes and some refactoring