some improvements, make more immutable