Added documentation, changed database interaction.