Refactoring some open codes, just for fun