Cleanup server code + move functions to amp.py