Changed a few lines to use instance methods instead. Final version.