Add environment class; Fixed error

Don't know how it wasn't crashing before but I was referencing the end()
of the list rather than the --end() of the list which caused a segment
fault.