Adds minor refactorings and fixings