Rough first pass at implementation. Works within swift.