refactored source for less ugly repo