generalizing code

minor modification