Fixed mistakes and minor bugs