Adapted implementation, renamed additional code.