Merged primitive algorithms to primitive.h
Bug fixes