updated with evegenys comments and 3/4 through repairs