Added Functions, cleaned up code slightly, added buy feature.