Code refactoring
Code refactoring and fixed a bug with wrong aligement