Update: Much more readable, easy to follow