code refactoring, added size options and fixed some offset problems