updated with neils code