Implemented GH-18 (in quite ugly way but whole thing is quite hack'y anyway).