Further implemented code from last pull request