Small fixes, refactoring.