Bug fixes small efficiency fixes