Improved sparse vector and moved switch statement