some improvements but gradient check still seems to fail