Fixed multiple bugs