using references: https://gist.github.com/WouterJ/5276618