cleaned up code, making more dynamic