refactor and beautification