Revision for #9, still needs testing