Add comments, improve code