Initial port from googlecode