Added inital code, modified for general purposes.