Fixed bugs. Added functionality