major overhaul; works better now
minor tweaks