fixed some issues based on Peter's review