added decltype and moved some stuff around