reimplementation in a more amateur way