Logic and API improvements, added docblocks