Code cleanup

cleaned up the code a bit, and fine-tuned item stacking. also avoids
stacking items if nothing to stack