added relevant code parts