mostly working version; finishing touches necessary