Fixes on top of changes made by Akshay for issue #52