Improved padding implementation + few other changes