Run perltidy on this, add some documentation