fixed bug in plots turning up blank and refactoring to do one selection per loop