Fixed the bug

Closes #516