Fix some merges and polish up the code