Incorporated Alexey's changes.