fixed size problem, refactored a bit, Fixes #1