modified with errors and checking length