base on Erik's solution(www.wrongway.org)