Added more flexible solution