Did some optimalization, code clean up