optimized references + namespaces and moved some code arround