optimize code a bit/documentation