Refactor, beautify code