cleaning up some code making it more dynamic