Fixed some bugs

The commit messages should be verbose enough to describe the changes done.