Made  several changes as asked in comments