Version 0.5

Condensed everything into separate functions so that the code could be
tested more easily. Still need to implement the changes promised in
update v0.4.