various minor code optmizations