Partially refactored, do not use