Cleaned up. Moved pi function to separate file. Shortened code.