Code snippets from fruityplay.com