Preliminary function writing. Haven't started threading