Fixed some issues and moved out to an RC file