Fix small bugs, minimize code