Bug corrections and small improvements