Minor bug and structural fixes