tested work, how to do sync code
http://stackoverflow.com/a/4631909