added crash prevention for edge cases