code reviewed and modified