Fix minor bugs and add small improvements