Initial commit with a copy from SGD extension