modified method to be more flexible