added Jon's code. TODO: remove if possible