Small improvements, optimized padding function