added guard to check length