added comments and typeclass definitions