Fix for bugs #17 and #18