Fully commented code, added serial printouts for troubleshooting