added checkLength helper method