added code. TODO: more comments