Rewrite: first working version; remove old files