Refoactored some code