update Readme file
refactoring to get rid of repeated code. eliminate some compiler warnings