Refactoring... though, it may be ugly