move the code into a mixin
document and clean up