Initial port from google code