Modified this to be more flexible