improved based on comments of victor