made some changes to make code work more dynamically