working + modified for topcoder