reformat code
minor code optimizations