Fixed small efficiency issues