refactor into smaller funcs, improved re, and msg formats