Added few functions and simple optimization