Big update 25/11/2013

Fix some bugs and minimize code