Moved some code to header.