Fixes bugs that arised from previous pull request