Moved code from googlecode