Refactor

@AvianFlu please review ASAP