fix implementation, add some comments and tune the padding