Finished first draft of code; still needs testing