Added a lot of optimization