redesigned & refactored the whole thing