Included the TypeII optimization routine, as well as some minor efficiency enhancements.

Signed-off-by: zauster <oliver.reiter@snapdragon.cc>