Fixes for issues 21, 25 and 27