Bug fix for issues 9, 12, 13