Fix bug (need refactoring)