cleanup and organized logic a bit