Code layout and small improvements