updated source to work properly with negative weights and finished documentation