refactor partially working, in need of overhaul.