Made some bug fixes