Fixed small mistakes in code.
Fixed Pad function.