fixed bugs and small improvements