rebased version of #9 Extra files from @jezdez