Cleaned up the layout code

- more robust free space calculation
- more robust used space commit
- cleaned up old code