Bug fixes; R tests